<?php
require RELATIVE_ROOT.'Classes/adodb/adodb-exceptions.inc.php';
require RELATIVE_ROOT.'Classes/adodb/adodb.inc.php';
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
/**
 * XiteCode database factory
 *
 * @copyright (c) 2006 A.Sleep <a.sleep@asleep.net> under the GNU GPL version 2
 * @author A.Sleep <a.sleep@asleep.net>
 * @package core
 * @access public
 */

class Database {

  function __construct()
  {
    trigger_error('Do not create an object with this class. Use Database::factory()', E_USER_ERROR);
    exit;
  }


  /**
   * Creates a database object
   *
   * @return object
   */

  public function factory()
  {
    try {
      $db = ADONewConnection($GLOBALS['cfg']['dbType']);
      $db->Connect($GLOBALS['cfg']['devHost'], $GLOBALS['cfg']['devUser'], $GLOBALS['cfg']['devPass'], $GLOBALS['cfg']['devDb']);
    }
    catch (exception $e) {
      Tools::dump($e);
      adodb_backtrace($e->gettrace());
      return false;
    }
    if (DEBUG) {
      $db->debug = true;
    }
    return $db;
  }


  /**
   * Does a unsafe to safe string escape
   *
   * @param string $string
   * @return string
   * @todo Detect DB type and do a escape for the given DB type
   */

  public function escape($string)
  {
    return mysql_real_escape_string($string);
  }

}

?>
